package com.klun.concTrueWar.RMI.Client;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NameClassPair;
import javax.naming.NamingException;
import java.rmi.RemoteException;
import java.util.Enumeration;

public class WarehouseClient {
    public static void main(String[] args) throws NamingException, RemoteException {
        Context namingContext = new InitialContext();
        System.out.println("RMI registry bindings");
        //NameClassPair是一个助手类：它包含绑定对象的名字和该对象所属类的名字
        Enumeration<NameClassPair> e = namingContext.list("rmi://localhost");
        while(e.hasMoreElements()){
            System.out.println(e.nextElement().getName());
        }
        // 客户端可以通过下面的方式，来指定服务器和远程对象的名字，
        // 以获得访问远程对象所需要的存根
        String url = "rmi://localhost/central_warehouse";
        Warehouse centralWarehouse = (Warehouse) namingContext.lookup(url);

        String descr = "Blackwell Toaster";
        double price = centralWarehouse.getPrice(descr);
        System.out.println(descr+":"+price);
    }
}
